package com.ccbft.msgcenter.producer.config;

import java.util.concurrent.TimeUnit;

import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.OkHttp3ClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
import okhttp3.OkHttpClient;

@Configuration
public class RestTemplateConfig {	
	
	@Bean("OkHttpClient")
	@LoadBalanced
	public RestTemplate OKHttp3RestTemplate() {
		OkHttpClient client = new OkHttpClient.Builder()
                .retryOnConnectionFailure(false)
                .connectTimeout(30, TimeUnit.SECONDS)
                .readTimeout(30, TimeUnit.SECONDS)
                .writeTimeout(30,TimeUnit.SECONDS)
                .build();
		return new RestTemplate(new OkHttp3ClientHttpRequestFactory(client));
	}

}
